package src

import (
	"os"
	"strings"

	"github.com/sirupsen/logrus"
)

var (
	tradeFront, quoteFront, loginInfo, brokerID, investorID, password, appID, authCode string
)

func init() {
	// 环境变量读取,赋值
	if tradeFront = os.Getenv("tradeFront"); tradeFront == "" {
		logrus.Fatal("未配置环境变量：tradeFront")
	}
	if quoteFront = os.Getenv("quoteFront"); quoteFront == "" {
		logrus.Fatal("未配置环境变量: quoteFront")
	}
	if loginInfo = os.Getenv("loginInfo"); loginInfo == "" {
		logrus.Fatal("未配置环境变量: loginInfo")
	}
	fs := strings.Split(loginInfo, "/")
	if len(fs) != 5 {
		logrus.Fatal("loginInfo 登录信息配置不正确")
	}
	brokerID, investorID, password, appID, authCode = fs[0], fs[1], fs[2], fs[3], fs[4]
	if !strings.HasPrefix(tradeFront, "tcp://") {
		tradeFront = "tcp://" + tradeFront
	}
	if !strings.HasPrefix(quoteFront, "tcp://") {
		quoteFront = "tcp://" + quoteFront
	}
}
